package com.gljx.web.controller.JournalController;

import com.gljx.web.Entity.JournalEntry.NotCheckBillsJournal;
import com.gljx.web.Entity.User;
import com.gljx.web.service.NotCheckBillsJournalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/")
public class NotCheckBillsJournalController {
	
	@Autowired
	private NotCheckBillsJournalService notCheckBillsJournalService;
	
	@RequestMapping(value="/queryNotCheckBillsJournal/look.action")
	public String selNotCheckBillsJournal(HttpServletRequest request,String beginTime,String endTime)throws Exception{
		//获取当前操作人
		HttpSession session=request.getSession();
		User user=(User) session.getAttribute("user"); 
		Calendar cale = Calendar.getInstance();// 得到一个Calendar的实例
 		 cale.add(Calendar.MONTH, 0);
 		 cale.set(Calendar.DAY_OF_MONTH, 1);
 		 Date resultDate = cale.getTime(); // 结果
 		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
 		 if(beginTime == null || beginTime.equals("")){
 			 beginTime = sdf.format(resultDate);
 		 }
 		 if(endTime == null  || endTime.equals("")){
 			 endTime = sdf.format(new Date());
 		 }
		List<NotCheckBillsJournal> notCheckBillsJournalList=notCheckBillsJournalService.selNotCheckBillsByCompanyId(user.getFcompanyid(),beginTime,endTime);
		/*System.out.println(notCheckBillsJournalList.size()+" =====>>>>");
		for (NotCheckBillsJournal notCheckBillsJournal : notCheckBillsJournalList) {
			System.out.println("部门: "+notCheckBillsJournal.getDepartmentName()+" 制单人: "+notCheckBillsJournal.getCrateName()+" 单据: "+notCheckBillsJournal.getBillName()+" 数量: "+notCheckBillsJournal.getNum());
		}*/
		//System.out.println("部门: "+notCheckBillsJournalList.get(0).getDepartmentName()+" 制单人: "+notCheckBillsJournalList.get(0).getCrateName()+" 数量: "+notCheckBillsJournalList.get(0).getNum());
		request.setAttribute("beginTime", beginTime);
		request.setAttribute("endTime", endTime);
		request.setAttribute("notCheckBillsJournalList", notCheckBillsJournalList);
		return "backHome/journaling/manageJournaling/notCheckBillsJournaling/notCheckBillsJournalingList";
	}
}
